package com.tianql.controller;


import com.tianql.core.ApiResult;
import com.tianql.pojo.StorageTbl;
import com.tianql.service.StorageServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/storage")
@Slf4j
public class StorageController {
    @Autowired
    private StorageServiceImpl storageService;

    @RequestMapping("deduct")
    public ApiResult deduct(@RequestParam("commodityCode") String commodityCode, @RequestParam("count") int count) {
        storageService.deduct(commodityCode, count);
        return new ApiResult(200, "扣减库存成功", null);
    }

    @RequestMapping("getCount")
    public ApiResult getCount(@RequestParam("commodityCode") String commodityCode) {
        StorageTbl one = storageService.lambdaQuery().eq(StorageTbl::getCommodityCode, commodityCode).one();
        return new ApiResult(200, "剩余数量", one.getCount());
    }
}
